<?php

/**
 * This file is part of the Pagizer package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @copyright   Copyright (c) 2010 Advisa (http://www.advisa.fr)
 * @author      Pagizer Core Team <team@pagizer.org>
 * @package     pagizer
 * @subpackage  medias
 */

class m_medias_actions_ResizePictureAction extends m_backoffice_extends_Action
{
	public function execute()
	{
		$media = f_document_Provider::getInstance()->getByModelAndUniqueId('medias/Media', $this->getRequestParameter("docId"), $this->getRequestParameter("docLang"));

        $value = $media->advancedResizePicture($this->getRequestParameter("picW"),
                                               $this->getRequestParameter("picH"),
                                               0,
                                               $this->getRequestParameter("cropW"),
                                               $this->getRequestParameter("cropH"),
                                               $this->getRequestParameter("offsetX"),
                                               $this->getRequestParameter("offsetY"),
                                               $this->getRequestParameter("bgColor", "000000"),
                                               $this->getRequestParameter("force", "0"));

        return ($value === true) ? "1" : $value;
	}

	public function validate()
	{
        return $this->getUserContext()->hasRight(array("backoffice_accessBo", "medias_Edit"));
	}
}